//
//  NavigationController.m
//  BackgroundDownload
//
//  Created by hodor on 2019/7/4.
//  Copyright © 2019 王松锋. All rights reserved.
//

#import "NavigationController.h"
#import "MainTabbarController.h"
@interface NavigationController ()

@end

@implementation NavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage *navBackImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#009ACD"]];
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setShadowImage:[[UIImage alloc] init]];
    [navBar setBackgroundImage:navBackImage forBarMetrics:UIBarMetricsDefault];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count) {
        MainTabbarController *tabBarController = (MainTabbarController *)self.tabBarController;
        [tabBarController setTabBarHiddenWithAnimaition:YES];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateHighlighted];
        [button sizeToFit];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    }
    
    if (![[super topViewController] isKindOfClass:[viewController class]]) {
        [super pushViewController:viewController animated:animated];
    }
}

- (void)back
{
    if ([self.topViewController respondsToSelector:@selector(back)]) {
        [self.topViewController back];
        
    } else {
        [self popViewControllerAnimated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
